﻿using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.Base;
using SmartWMS.Domain.SystemSet;
using SmartWMS.Server.Repository;
using SmartWMS.Server.SystemSets.ResetPwdServices.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartWMS.Server.SystemSets.ResetPwdServices
{
    public class ResetService : IResetService
    {
        private readonly IRepository<Staff> _resetRepository;

        public ResetService(IRepository<Staff> resetRepository)
        {
            _resetRepository = resetRepository;
        }

        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>

        public async Task<Response<bool>> ResetPassword(StaffPwdInput input)
        {

            var staff = await _resetRepository.GetEntityByIdAsync(new KeyEntity { Id = input.Id });
            var result = staff.MapTo<StaffPwdInput>();

            if (staff == null)
            {
                return Response<bool>.Ok(false);
            }

            input.StaffPwd = MD5Helper.Get16MD5Two(input.StaffPwd);
            staff.StaffPwd = input.StaffPwd;
            var i = await _resetRepository.UpdateAsync(staff);
            return Response<bool>.Ok(i > 0);


        }
    }
}
